<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>用户编辑</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <div class="layui-tab" style="margin:0 70px 70px 70px;">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item layui-pop-tworow marlr50">
                        <input type="hidden" class="form-control id" id="id" name="id" value="${sysUser.id}"/>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" value="${sysUser.name}" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-pop-tworow marlr50">
                        <label class="layui-form-label">&nbsp;手机号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="phone" required lay-verify="required|phone" placeholder="请输入手机号" value="${sysUser.phone}" maxlength="11"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-pop-tworow marlr50">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;登&nbsp;录&nbsp;名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="loginName" required lay-verify="required" placeholder="请输入登录名" value="${sysUser.loginName}"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <#if sysUser.password == null>
                    <div class="layui-form-item layui-pop-tworow marlr50">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;登录密码：</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" required lay-verify="required" placeholder="请输入登录密码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    </#if>
                    <div class="layui-form-item marlr50" id="roleId">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</label>
                        <div class="layui-input-block">
                            <#list list as role>
                                <input type="checkbox" name="roleList" value="${role.id}" lay-skin="primary" title="${role.roleName}" <#list urList as userRole> <#if userRole.userId=sysUser.id><#if userRole.roleId=role.id>checked</#if></#if></#list>>
                            </#list>
                        </div>
                    </div>
                    <div class="layui-form-item marlr50">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;用户类型：</label>
                        <div class="layui-input-block">
                            <select name="userType" id="userType" lay-filter="userType"></select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-pop-tworow marlr50">
                        <label class="layui-form-label">头&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;像：</label>
                        <!--单图片开始-->
                        <div class="layui-input-block cy-uploadpic-ctn" id="headLogo" style=" float:left;margin-left:0px!important;position:relative;"></div>
                    </div>
                    <div class="layui-form-item marlr50">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="orgId" id="orgId" value="<#list orgList as org><#if org_index==0>${org.orgId}</#if><#if org_index gt 0>,${org.orgId}</#if></#list>"/>
                            <input type="text" name="orgName" id="orgName" data-init-ids="${sysUser.orgId}" class="layui-input orgSelect" data-result-id="orgId"
                                   id="orgName" data-result-name="orgName" data-selector-type="mult" value="<#list orgList as org><#if org_index==0>${org.orgName}</#if><#if org_index gt 0>,${org.orgName}</#if></#list>"/>
                        </div>
                    </div>
                    <#if isAccount != '2'>
                    <div class="layui-form-item marlr50">
                        <label class="layui-form-label">&nbsp开启通用账号：</label>
                        <div class="layui-input-block">
                            <#if isAccount == '0'>
                            <input type="radio" lay-filter="account" name="isAccount" value="0" title="否" checked>
                            <input type="radio" lay-filter="account" name="isAccount" value="1" title="是">
                            <#elseif isAccount == '1'>
                            <input type="radio" name="isAccount" value="1" title="是" checked>
                            </#if>
                        </div>
                    </div>
                    <div class="layui-form-item marlr50 <#if isAccount == '0'>layui-hide</#if> showAccount">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp公众号：</label>
                        <div class="layui-input-block">
                            <select name="accountId" id="accountId">
                                <#if isAccount == '0'>
                                <option value="">请选择</option>
                                </#if>
                                <#list wxAccountList as p>
                                <#if p.id == sysUser.accountId>
                                <option value="${p.id}" selected>${p.name}</option>
                                <#else>
                                <option value="${p.id}">${p.name}</option>
                                </#if>
                                </#list>
                            </select>
                        </div>
                    </div>
                    </#if>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
            <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
            <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'page', 'dialog', 'baseutil', 'fileUtil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            page = layui.page,
            dialog = layui.dialog,
            baseutil = layui.baseutil,
            fileUtil = layui.fileUtil;

        form.on('radio(account)', function (data) {
            if (data.value === '0') {
                $('.showAccount').addClass("layui-hide");
            } else if (data.value === '1') {
                $('.showAccount').removeClass("layui-hide");
            }
        });

        //单图片上传
        fileUtil.uploadImage('headLogo', "sys/user", "${sysUser.headLogo}");

        //初始化用户类型
        page.initDict("sys_user_type", function (dictData) {
            page.showDict($("#userType"), page.aceeptDictContentList(dictData, "sys_user_type"), "", '${sysUser.userType}');
        });

        //监听提交
        form.on('submit(submitBtn)', function (data) {
            //角色封装
            var ids = [];//接收对象
            var r = document.getElementsByName("roleList");
            for (var i = 0; i < r.length; i++) {
                if (r[i].checked) {
                    ids.push(r[i].value);
                }
            }
            if (ids == null || ids.length <= 0) {
                dialog.msg("请选择角色");
                return false;
            }
            data.field.roleId = ids.join(",");
            if ('isAccount' === '0' && data.field.isAccount === '0') {
                data.field.accountId = '';
            }
            baseutil.post("/sysUser/addOrUpdate", data.field, function (result) {
                if (result.code === 0) {
                    $("#save").click();
                } else {
                    dialog.msg(result.msg);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>